/*
							Copyright (C) 2010  Alourien Team
									
						This file is part of the Alourien Engine.

    The Alourien Engine is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    The Alourien Engine is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with the Alourien Engine.  If not, see <http://www.gnu.org/licenses/>.
	
 *File Name:Matrix2Dimp.cpp
 *Programmer Name:Jose Castellano
 *Date of Last Update: 10/18/2010
 *
 *Purpose:This Program is to create a two dimensional 
 * Matrix to be used in later programs
 *
 *Basic Info:It Needs the Matrix2D header.
 *
 *UPDATES:
 *1)Created the Program and documentation.
 *  Date:10/18/2010 Updater: Jose Castellano
 *
 *
 */

#include "Matrix2D.h"

namespace Alourien
{
	Matrix2D::Matrix2D(void)
	{
		for(int n = 0; n < 3; ++n)
		{
			for(int i = 0; i < 3; i++)
			{
				matArray[n][i] = 0;
			}
		}
	}


	Matrix2D::~Matrix2D(void)
	{
	}
	
	//Creates the Identity matrix that will be used later on
	void Matrix2D::MakeIdentity()
	{
		for(int i = 0; i < 3; i++)
			{
				matArray[i][i] = 1;
			}
	}


	//This function is to get the values and set them into the matrix
	//It allows for a faster initialization, rather than setting in the main
	//using two lines of code.
	void Matrix2D::MatrixSet(float xValue, float yValue)
	{
		matArray[0][2] = xValue;
		matArray[1][2] = yValue;
	}
	
	//Overload of the + operator but for 2 Dimensional Matrix
	//Returns a 2 dimensional Matrix
	Matrix2D Matrix2D::operator+(const Matrix2D& matrix2) const
	{
		Matrix2D tempData;

		for(int n = 0; n < 3; ++n)
		{
			for(int i = 0; i < 3; i++)
			{
				tempData.matArray[n][i] = this->matArray[n][i] + matrix2.matArray[n][i];
			}
		}

		return tempData;
	}
	
	//Overload of the * operator but for 2 Dimensional Matrix
	//Returns a 2 dimensional Matrix
	Matrix2D Matrix2D::operator*(const Matrix2D& matrix2) const
	{
		Matrix2D tempData;
		float temp = 0;
		float temp2 = 0;
		float temp3 = 0;
		int m = 0;

		for(int n = 0; n < 3; ++n)
		{
			for(int i = 0; i < 3; i++)
			{
				temp += this->matArray[n][i] * matrix2.matArray[i][m];
				temp2 += this->matArray[n][i] * matrix2.matArray[i][m+1];
				temp3 += this->matArray[n][i] * matrix2.matArray[i][m+2];
			}
			
			tempData.matArray[n][0] = temp;
			tempData.matArray[n][1] = temp2;
			tempData.matArray[n][2] = temp3;
		}

		return tempData;
	}
}